package org.yeyu.model;

import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/**
 * 表头行设置项
 * 包含工作表名称和对应的表头行号
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class HeaderRowItem {
    private static final Logger logger = LogManager.getLogger(HeaderRowItem.class);

    private SimpleStringProperty sheetName;
    private SimpleIntegerProperty tableRow;

    /**
     * 构造函数
     * @param sheetName 工作表名称，不能为空
     */
    public HeaderRowItem(String sheetName) {
        if (sheetName == null || sheetName.trim().isEmpty()) {
            throw new IllegalArgumentException("工作表名称不能为空");
        }
        this.sheetName = new SimpleStringProperty(sheetName);
        this.tableRow = new SimpleIntegerProperty(1); // 默认表头行为第1行
    }

    /**
     * 设置表头行号
     * @param row 表头行号，必须大于0
     */
    public void setTableRow(int row) {
        if (row <= 0) {
            logger.warn("表头行号必须大于0，但收到: {}", row);
            throw new IllegalArgumentException("表头行号必须大于0");
        }
        this.tableRow.set(row);
    }

    @Override
    public String toString() {
        return sheetName.get() + " - 第 " + tableRow.get() + " 行";
    }
}
